/**
 * 
 */
package com.scaffold.springmvc.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.scaffold.commons.spring.BasicAction;
import com.scaffold.commons.web.WebUtil;

/**
 * @author wangjg
 */
@Controller
public class Base64Action extends BasicAction {
	
	@RequestMapping("/base64/decode.xhtml")
	public void upload(String text, HttpServletRequest request, HttpServletResponse response) throws IOException{
		if(text!=null){
			WebUtil.setDownloadHeader(request, response, "base64_file", null);
	        byte[] buf = Base64.decodeBase64(text.getBytes("utf-8"));
	        response.getOutputStream().write(buf);
		}
	}

}
